home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 15 / marylamb.zip / MUSIC.C < prev    next >
C/C++ Source or Header  |  1986-11-16  |  5KB  |  181 lines

  1. /* */
  2. /* Library application source file. */
  3. /* */
  4. /*
  5.  *    Application Note 10.  Windows "Library" utility.
  6.  *
  7.  *
  8.  *    Author:    John C. Pollock
  9.  *           OEM Customer Support Engineer
  10.  *    Date:       1-5-85
  11.  *    Processor: IBM AT. 640K EGA w/ Enhanced Color Display
  12.  *
  13.  *
  14.  *    This application demonstrates how a windows code library should
  15.  *    be built.  LIBRARY is a poor name since what is actually built is
  16.  *    a sharable executable .EXE file.
  17.  *
  18.  */
  19.  
  20. #include "windows.h"
  21. #include "tunes.h"
  22.  
  23. extern FAR PASCAL LocalInit();
  24.  
  25. #ifdef COMMENT
  26.  
  27. The body of a Windows sharable code library is illustrated by LIBRARY.C.
  28.  
  29. library.obj: library.c
  30.     cc -u -c -AM -Gsw -Oas -Zped library.c
  31.  
  32. The entry point for the library is "main()".  "main()" is called when
  33. the library is first loaded into memory by the Windows loader.    The
  34. use of "main()" as the library entry point is arbitrary.  Any procedure
  35. may be used as an entry point.    The entrypoint is specified by a
  36. "module definition entry point" link text record.  The use of "main()"
  37. is convenient since it is familiar to "C" programmers.
  38.  
  39. In reality, the entry point for any Microsoft "C" program is "__astart".
  40. "__astart" then calls "main()".  The LIBAUX.ASM file shows how one
  41. generates a "module definition entry point" record.  Any assembler
  42. "END" directive that contains an identifier, e.g. "END __astart"
  43. generates a "module definition entry point" record.
  44.  
  45. libaux.obj: libaux.asm
  46.     masm -Mx -I.\ -I\LIB -D?MLIBW libaux.asm;
  47.  
  48. The following link line produces the sharable code library MUSIC.EXE
  49. from LIBRARY.OBJ.  Windows will load this code if any dynamic link
  50. records point to it.  An object library of "dynamic link records"
  51. is produced by IMPLIB.EXE from LIBRARY.DEF.  An application links
  52. to the dynamic link records in MUSIC.LIB rather than to the code
  53. that is in MUSIC.EXE.
  54.  
  55. music.exe: libaux.obj library.obj library.def
  56.     link4 libaux library,music,music/map/li, mlibw mwlibc/nodef, library.def;
  57.     mapsym music
  58.     implib music.lib library.def
  59.  
  60. The TESTER.EXE program is a very small windows program that dynamically
  61. links to MUSIC.EXE.
  62.  
  63. tester.obj: tester.c
  64.     cc -u -c -Asnw -Gsw -Oas -Zped tester.c
  65.  
  66. tester.exe: tester.obj
  67.     link4 tester,,,music.lib slibw swlibc/map/li,tester.def;
  68.     mapsym tester
  69.  
  70. #endif
  71.  
  72.  
  73. /*
  74. ** PlayMusic - Windows music interpreter.
  75. **
  76. ** PlayMusic implements a simple Windows music interpreter.  The interpreter
  77. ** is designed such that each music operand fetches its own arguments and
  78. ** increments the music pointer "lpmusic".  Operands to the music interpreter
  79. ** are negative integers each of which encodes a single Windows SOUND module
  80. ** procedure call.  Non-negative operands implicitly encode SetVoiceNote
  81. ** calls ( since they are the most common calls ).
  82. **
  83. */
  84. BOOL FAR PASCAL PlayMusic( lpmusic )
  85. LPTUNES lpmusic;
  86. {
  87.     NOTES t;
  88.     for (  ;;  )
  89.     switch ( t = *lpmusic++ ) {
  90.  
  91.         case OPENSOUND:
  92.         OpenSound();
  93.         break;
  94.  
  95.         case CLOSESOUND:
  96.         CloseSound();
  97.         break;
  98.  
  99.         case SETVOICEQUEUESIZE:
  100.         SetVoiceQueueSize( *lpmusic, *(lpmusic+1) );
  101.         lpmusic += 2;
  102.         break;
  103.  
  104.         case SETVOICEACCENT:
  105.         SetVoiceAccent( *lpmusic, *(lpmusic+1), *(lpmusic+2), *(lpmusic+3), *(lpmusic+4) );
  106.         lpmusic += 5;
  107.         break;
  108.  
  109.         case SETVOICEENVELOPE:
  110.         SetVoiceEnvelope( *lpmusic, *(lpmusic+1), *(lpmusic+2) );
  111.         lpmusic += 3;
  112.         break;
  113.  
  114.         case SETSOUNDNOISE:
  115.         SetSoundNoise( *lpmusic, *(lpmusic+1) );
  116.         lpmusic += 2;
  117.         break;
  118.  
  119.         case SETVOICESOUND:
  120.         SetVoiceSound( *lpmusic, *(lpmusic+1), *(lpmusic+2) );
  121.         lpmusic += 3;
  122.         break;
  123.  
  124.         case STARTSOUND:
  125.         StartSound();
  126.         break;
  127.  
  128.         case STOPSOUND:
  129.         return StopSound();
  130.  
  131.         case WAITSOUNDSTATE:
  132.         WaitSoundState( *lpmusic++ );
  133.         break;
  134.  
  135.         case SYNCALLVOICES:
  136.         SyncAllVoices();
  137.         break;
  138.  
  139.         case COUNTVOICENOTES:
  140.         CountVoiceNotes( *lpmusic++ );
  141.         break;
  142.  
  143.         case GETTHRESHOLDEVENT:
  144.         GetThresholdEvent();
  145.         break;
  146.  
  147.         case GETTHRESHOLDSTATUS:
  148.         GetThresholdStatus();
  149.         break;
  150.  
  151.         case SETVOICETHRESHOLD:
  152.         SetVoiceThreshold( *lpmusic, *(lpmusic+1) );
  153.         lpmusic += 2;
  154.         break;
  155.  
  156.         default:
  157.         SetVoiceNote( t, *lpmusic, *(lpmusic+1), *(lpmusic+2) );
  158.         lpmusic += 3;
  159.         break;
  160.         }
  161. }
  162.  
  163. HANDLE modulehandle;
  164.  
  165. int FAR PASCAL main( argc, argv )
  166. register int argc;
  167. HANDLE FAR *argv;
  168. {
  169.     /*
  170.        ArgC     == 5;
  171.        ArgV+0     - automatic data segment.
  172.        ArgV+1     - size of heap.
  173.        ArgV+2     - module handle.
  174.        ArgV+3:4  - command line farp.
  175.     */
  176.     if ( *argv )
  177.     /* Initialize DS ( *argv ) to have local heap of *(argv+1) size. */
  178.     LocalInit( (WORD)*argv, (char NEAR *)0, (char NEAR *)*(argv+1) );
  179.     modulehandle = *(argv+2);
  180. }
  181.